package com.liu.search.controller;

import com.liu.common.entity.PageResult;
import com.liu.common.entity.Result;
import com.liu.common.status.CodeEnum;
import com.liu.search.pojo.Article;
import com.liu.search.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2019/8/20 0020.
 */
@RestController
@RequestMapping("/article")
@CrossOrigin
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @PostMapping
    public Result save(@RequestBody Article article){

        articleService.add(article);
        return new Result(true,CodeEnum.OK.getCode(),"添加成功");

    }
     @RequestMapping(value = "/{page}/{rows}",method = RequestMethod.GET)
    public Result findKey(String key,@PathVariable  int page,@PathVariable  int rows){
         Page<Article> pages = articleService.findKey(key,page,rows);

        return  new Result(true,CodeEnum.OK.getCode(),"查询成功",new PageResult<Article>(pages.getTotalElements(),pages.getContent()));
    }

}
